package com.pzhuweb.sgblog.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pzhuweb.sgblog.domain.entity.Role;
import com.pzhuweb.sgblog.mapper.RoleMapper;
import com.pzhuweb.sgblog.service.RoleService;
import com.pzhuweb.sgblog.domain.utils.SecurityUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 鄧浩奇
 * @classname RoleServiceImpl
 * @description
 * @since 2023/8/6 17:34
 **/

@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Override
    public List<String> getRolesKeyByUserId(Long id) {
        // 判断是不是管理员，如果是则返回admin
        if (SecurityUtils.isAdmin()) {
            List<String> roleKeys = new ArrayList<>();
            roleKeys.add("admin");
            return roleKeys;
        }
        // 否则，查询当前用户具有的角色信息
        return getBaseMapper().selectRoleKeysByUserId(id);
    }
}
